package laf.behaviours;

import jade.core.Agent;
import jade.core.behaviours.OneShotBehaviour;
import laf.env.EnvObject;
import laf.env.Enviroment;
import laf.env.ObjectIdentifier;
import laf.env.Observation;
import laf.env.State;
import laf.time.TimeManager;
import laf.time.Timer;

public class ObservationBehaviour extends OneShotBehaviour {

	private static final long serialVersionUID = -2689197964222133808L;
	private Observation observation;
	private ObjectIdentifier objectId;

	public ObservationBehaviour(Agent agent, ObjectIdentifier objectId) {
		super(agent);
		this.objectId = objectId;
	}

	@Override
	public void action() {
		if (objectId != null) {
			EnvObject obj = Enviroment.getInstance().getObject(objectId);
			if (obj != null) {				
				State state = obj.getState();
				long time = obj.getStateTime();
								
				observation = new Observation(time, objectId, state);
				handleResult(observation);

			} else {
				handleError("Object does not exists");
			}
		} else {
			handleError("Object identifier must be set");
		}
	}

	protected void handleResult(Observation observation) {

	}

	protected void handleError(String errorMsg) {
		throw new IllegalArgumentException(errorMsg);
	}

}
